var checkFileAllResv = 0;
var checkFileCheckout = 0;
var checkFilePenCheckIn = 0;
var checkFileNoShow = 0;
var checkFileTemp = 0;
var checkFileCancel =0;
var checkFilePenCheckOut = 0;
var checkFileExpress = 0;
var checkFileDeposits =0;
var checkFilePaymentTrack = 0
var checkFileGuest =0;
var checkFilePrintEmail = 0;
function objToStr(obj){
	for (var k in obj){
		if (obj.hasOwnProperty(k)){
			if(k=="OtherChargeList"||k=="payment"||k=="ChargeList"){
	    		var objC =  obj[k];
	    		var objPut = new Array();
	    		for(var c = 0;c<objC.length;c++){
	    			for(var j in objC[c]){
		    			if(objC[c].hasOwnProperty(j)){
		    				objC[c][j] = String(objC[c][j]);
		    			}
		    		}
	    			objPut.push(objC[c]);
	    		}
	    		obj[k] = objPut;
	    	}else{
	    		obj[k] = String(obj[k]);
	    	}
		}
	}
	return obj;
}

function CreateMenu(title, id) {
	//waitingDialog({});
	var Tabs = {};
	var tmpData = getTabsData(id);
	if(tmpData != null)
	{
		Tabs = tmpData;
		DisplayframeReserved(Tabs.page);
		setTimeout(function(){showNumberall_reservation();},50);
	}else{
		TabsData.push(Tabs);
		Tabs.type = "Manage";
		Tabs.resId = id;
		Tabs.page = id;
		Tabs.title = title;
		$(".select").attr("class","showdisplay");
		var str = "<div  id=\"tappage_roommanage_menu_{0}\" onclick=\"DisplayframeReserved(title)\"class=\"select\" refid=\"{1}\" title=\"{2}\" useprint="+title+" >&nbsp;{3}&nbsp;&nbsp;</div><img src=\"/images/components/tappage/cancel.png\" width=\"13px\" height=\"13px\" title=\"{4}\"  onclick=\"CloseTapPage(title)\" class =\"closebutton\">";
		$("#tabs").append(str.format(
			Tabs.page,
			Tabs.page,
			Tabs.page,
			Tabs.title,
			Tabs.page
		));
		DisplayDetail();
		setTimeout(function(){showNumberall_reservation();},50);
	}
}
var bottomPrintClose = "";
function RenderRoomManagementPage(Tabs)
{
	var id = Tabs.page;
	loadRoomManagementElement(id,function(){
		set_BotButton(id,Tabs.page);
		$("#tappage").append(
			"<div id=\"tappage_newpage_" + Tabs.page + "\">"
				+ $("[pageRoomManageMent=" + id + "_Page]").html()
				+ bottomPrintClose + "</div>");
		$("#tappage").css("display","");
		displayRoommanagement(id);
	});
	
}
function set_BotButton(id){
	if(id=="CheckInListRoomManageMent"){
		var services = [];
		services.push(["/popupService",{doClass:"loadSalutation"},"Salutation",null]);
		services.push(["/modearrivalService",{func: "loadAllModeArrival"},"ArrivalMode",null]);
		loadSharedDataIfNotExist(services,null);
		bottomPrintClose = '<center>'
			+ '<div>'
			+ '<table  class="printCloseButton" >'
			+ '<tr>'
			+ '<td>'
			+ '<center>'
			+ '<input type="button" name="cancellation_reserved" setButton="tempReservation" class="buttonBottom" onclick="AddToNewGroup()" value='
			+ btnAddToNewGroupRoomManageMent
			+ '>'
			+ '<input type="button" name="cancellation_reserved" setButton="tempReservation" class="buttonBottom" onclick="confirmRemoveFromGroupFunction()" value='
			+ btnRemoveFromGroupRoomManageMent
			+ '>'
			+ '<input type="button" name="cancellation_reserved" setButton="tempReservation" class="buttonBottom" onclick="confirmAddFromGroupFuction()" value='
			+ btnAddToGroupRoomManageMent
			+ '>'
			+ '<input type="button" name="cancellation_reserved" setButton="tempReservation" class="buttonBottom" onclick="printDiv(tappage,'+id+')" value='
			+ btnPrintRoomManageMent
			+ '>'
			+ '<input type="button" name="closePage"  class="buttonBottom" title='
			+ id + ' value=' + btnCloseRoomManageMent
			+ ' onclick="CloseTapPage(title)">' + '</center>' + '</td>'
			+ '</tr>' + '</table>' + '</div>' + '</center>';
	}else if(id=="GuestNameListRoomManageMent"){
		bottomPrintClose = '<center>'
		+ '<div>'
		+ '<table  class="printCloseButton"  border="1">'
		+ '<tr>'
		+ '<td>'
		+ '<center>'
		+ '<input type="button" name="cancellation_reserved" setButton="tempReservation" class="buttonBottom" onclick="printDiv(tappage,'+id+')" value='
		+ btnPrintRoomManageMent
		+ '>'
		+ '<select class="exportBtn" id="optionExport"><option value="Excel">Excel</option><option value="Csv">Csv</option><option value="Pdf">PDF</option></select>'
		+ '<input type="button" id="export" setButton="tempReservation" class="buttonBottom" onclick="exportCsv()" value='
		+ 'นำออก'
		+ '>'
		+ '<input type="button" name="closePage"  class="buttonBottom" title='
		+ id + ' value=' + btnCloseRoomManageMent
		+ ' onclick="CloseTapPage(title)">' + '</center>' + '</td>'
		+ '</tr>' + '</table>' + '</div>' + '</center>';
	}else{
	 bottomPrintClose = '<center>'
			+ '<div>'
			+ '<table  class="printCloseButton" >'
			+ '<tr>'
			+ '<td>'
			+ '<center>'
			+ '<input type="button" name="cancellation_reserved" setButton="tempReservation" class="buttonBottom" onclick="printDiv(tappage,'+id+')" value='
			+ btnPrintRoomManageMent
			+ '>'
			+ '<input type="button" name="closePage"  class="buttonBottom" title='
			+ id + ' value=' + btnCloseRoomManageMent
			+ ' onclick="CloseTapPage(title)">' + '</center>' + '</td>'
			+ '</tr>' + '</table>' + '</div>' + '</center>';
	}
}

function loadRoomManagementElement(id,callback){
	if(id=="CheckInListRoomManageMent") dynamicLoadRoomManagementElement("allreservation.jsp","CheckInListRoomManageMent_Page",callback);
	else if(id=="CheckOutListRoomManageMent") dynamicLoadRoomManagementElement("checkout.jsp","CheckOutListRoomManageMent_Page",callback);
	else if(id=="CheckInPendingListRoomManageMent") dynamicLoadRoomManagementElement("pendingCheckin.jsp","CheckInPendingListRoomManageMent_Page",callback);
	else if(id=="NoShowListRoomManageMent") dynamicLoadRoomManagementElement("noshow.jsp","NoShowListRoomManageMent_Page",callback);
	else if(id=="TempListRoomManageMent") dynamicLoadRoomManagementElement("temp.jsp","TempListRoomManageMent_Page",callback);
	else if(id=="CancelReservationListRoomManageMent") dynamicLoadRoomManagementElement("cancelReservation.jsp","CancelReservationListRoomManageMent_Page",callback);
	else if(id=="CheckOutPendingListRoomManageMent") dynamicLoadRoomManagementElement("pendingCheckout.jsp","CheckOutPendingListRoomManageMent_Page",callback);
	else if(id=="CheckOutExpressListRoomManageMent") dynamicLoadRoomManagementElement("expressCheckout.jsp","CheckOutExpressListRoomManageMent_Page",callback);
	else if(id=="BookingDepositsListRoomManageMent") dynamicLoadRoomManagementElement("deposits.jsp","BookingDepositsListRoomManageMent_Page",callback);
	else if(id=="PaymentTrackerListRoomManageMent") dynamicLoadRoomManagementElement("paymentTrack.jsp","PaymentTrackerListRoomManageMent_Page",callback);
	else if(id=="GuestNameListRoomManageMent") dynamicLoadRoomManagementElement("guest.jsp","GuestNameListRoomManageMent_Page",callback);
	else { callback(); }
	function dynamicLoadRoomManagementElement(file,pagename,callback){
		if($("div[forload=newpageRoomManagement] [pageRoomManageMent="+pagename+"]").size() == 0){
			var div = $("<div>");
			$("div[forload=newpageRoomManagement]").append(div);
			div.load("/components/newpage/roomManagementList/"+file,function(){callback();})
		}else
			callback();
	}
}
function displayRoommanagement(id){
	if(checkFilePrintEmail==0){
		$.getScript("/js/print/printRoomManageMent.js")
		.done(function() { checkFilePrintEmail=1; })
		.fail(function() { simpleDialog("Error"); });
		$.getScript("/js/print/printRoomManageMentCheckout.js")
		.done(function() { checkFilePrintEmail=1; })
		.fail(function() { simpleDialog("Error"); });
		$.getScript("/js/sendEmail/sendEmailRoomManageMent.js")
		.done(function() { checkFilePrintEmail=1; })
		.fail(function() { simpleDialog("Error"); });
	}
	//
	if (id == "CheckOutListRoomManageMent") {
		$("#menulist").attr("style","display:none");
		if(checkFileCheckout==0){
			$.getScript("/js/components/roomManagementList/checkout.js")
			.done(function() { getReservationRoomManageMent(id); checkFileCheckout=1; })
			.fail(function() { simpleDialog("Error"); });
		}else{
			if(oldObjArrayCheckout.length==0){
				getReservationRoomManageMent(id);
			}else{
				showDataResRoomManageMent(JSON.stringify(oldObjArrayCheckout));
				showDataResRoomManageMentSetPageCheckout(JSON.stringify(oldObjArrayCheckout));
			}
		}
	} else if (id == "CheckInListRoomManageMent") {
		$("#menulist").attr("style","display:none");
		if(checkFileAllResv==0){
			$.getScript("/js/components/roomManagementList/all_reservation.js")
			.done(function() { checkFileAllResv = 1; getReservationRoomAllManageMent(id); })
			.fail(function() { simpleDialog("Error"); });
		}else{
			if(oldObjArrayAllReservation.length==0){
				getReservationRoomAllManageMent(id);
			}else{
				showDataResRoomAllManageMent(JSON.stringify(oldObjArrayAllReservation));
				showDataResRoomManageMentSetPageAll(JSON.stringify(oldObjArrayAllReservation));
			}
		}
	} else if (id == "CheckInPendingListRoomManageMent"){
		$("#menulist").attr("style","display:none");
		if(checkFilePenCheckIn==0){
			$.getScript("/js/components/roomManagementList/pending_checkin.js")
			.done(function() { getReservationRoomCheckinPendingManageMent(id); })
			.fail(function() { simpleDialog("Error"); });
			checkFilePenCheckIn=1;
		}else{
			if(oldObjArrayCheckin.length==0){
				getReservationRoomCheckinPendingManageMent(id);
			}else{
				showDataResRoomCheckinPendingManageMent(JSON.stringify(oldObjArrayCheckin));
			}
		}
	} else if (id == "TempListRoomManageMent") {
		$("#menulist").attr("style","display:none");
		if(checkFileTemp==0){
			$.getScript("/js/components/roomManagementList/temp_reservation.js")
			.done(function() { getReservationRoomTempManageMent(id); })
			.fail(function() { simpleDialog("Error"); });
			checkFileTemp=1;
		}else{
			if(oldObjArrayTemp.length==0){
				getReservationRoomTempManageMent(id);
			}else{
				showDataResRoomTempManageMent(JSON.stringify(oldObjArrayTemp));
			}
		}
	} else if (id == "CancelReservationListRoomManageMent") {
		$("#menulist").attr("style","display:none");
		if(checkFileCancel==0){
			$.getScript("/js/components/roomManagementList/cancel_reservation.js")
			.done(function() { getReservationRoomCancelResvManageMent(id); })
			.fail(function() { simpleDialog("Error"); });
			checkFileCancel=1;
		}else{
			if(oldObjArrayCancel.length==0){
				getReservationRoomCancelResvManageMent(id);
			}else{
				showDataResRoomCancelResvManageMent(JSON.stringify(oldObjArrayCancel));
			}
		}
	} else if (id == "CheckOutPendingListRoomManageMent") {
		$("#menulist").attr("style","display:none");
		if(checkFilePenCheckOut==0){
			$.getScript("/js/components/roomManagementList/pending_checkout.js")
			.done(function() { getReservationRoomManageMentCheckoutPending(id); })
			.fail(function() { simpleDialog("Error"); });
			checkFilePenCheckOut=1;
		}else{
			if(oldObjArrayPendingCheckout.length==0){
				getReservationRoomManageMentCheckoutPending(id);
			}else{
				showDataResRoomManageMentCheckoutPending(JSON.stringify(oldObjArrayPendingCheckout));
			}
		}
	} else if (id == "BookingDepositsListRoomManageMent") {
		$("#menulist").attr("style","display:none");
		if(checkFileDeposits==0){
			$.getScript("/js/components/roomManagementList/deposits_reservation.js")
			.done(function() { getReservationRoomBookingDepositsManageMent(id); })
			.fail(function() { simpleDialog("Error"); });
			checkFileDeposits =1;
		}else{
			if(oldObjArrayDeposits.length==0){
				getReservationRoomBookingDepositsManageMent(id);
			}else{
				showDataResRoomBookingDepositsManageMent(JSON.stringify(oldObjArrayDeposits));
			}
		}
	} else if (id == "PaymentTrackerListRoomManageMent") {
		$("#menulist").attr("style","display:none");
		if(checkFilePaymentTrack==0){
			$.getScript("/js/components/roomManagementList/paymenttracker_reservation.js")
			.done(function() { getReservationRoomPaymentTrackerManageMent(id); })
			.fail(function() { simpleDialog("Error"); });
			checkFilePaymentTrack=1;
		}else{
			if(oldObjArrayPaymentTracker.length==0){
				getReservationRoomPaymentTrackerManageMent(id);
			}else{
				showDataResRoomPaymentTrackerManageMent(JSON.stringify(oldObjArrayPaymentTracker));
			}
		}
	} else if (id == "GuestNameListRoomManageMent") {
		$("#menulist").attr("style","display:none");
		if(checkFileGuest==0){
			$.getScript("/js/components/roomManagementList/guest_reservation.js")
			.done(function() { getReservationRoomManageMentGuestName(id); })
			.fail(function() { simpleDialog("Error"); });
			checkFileGuest = 1;
		}else{
			if(oldObjArrayGuest.length==0){
				getReservationRoomManageMentGuestName(id);
			}else{
				showDataResRoomManageMentGuestName(JSON.stringify(oldObjArrayGuest));
			}
		}
	} else if (id == "CheckOutExpressListRoomManageMent") {
		$("#menulist").attr("style","display:none");
		if(checkFileExpress==0){
			$.getScript("/js/components/roomManagementList/express_reservation.js")
			.done(function() { getReservationRoomManageMentCheckOutExpress(id); })
			.fail(function() { simpleDialog("Error"); });
			checkFileExpress=1;
		}else{
			if(oldObjArrayExpress.length==0){
				getReservationRoomManageMentCheckOutExpress(id);
			}else{
				showDataResRoomManageMentCheckOutExpress(JSON.stringify(oldObjArrayExpress));
			}
		}
	} else if (id == "NoShowListRoomManageMent") {
		$("#menulist").attr("style","display:none");
		if(checkFileNoShow==0){
			$.getScript("/js/components/roomManagementList/noshow_reservation.js")
			.done(function() { getReservationRoomNoShowManageMent(id); })
			.fail(function() { simpleDialog("Error"); });
			checkFileNoShow=1;
		}else{
			if(oldObjArrayNoShow.length==0){
				getReservationRoomNoShowManageMent(id);
			}else{
				showDataResRoomNoShowManageMent(JSON.stringify(oldObjArrayNoShow));
			}
		}
	}
}
function CloseTapPage(title) {
	clearArrayDataRoommanagement(title);
	var refid = $("#tappage_roommanage_menu_" + title).attr("refid");
	TabsData.splice(TabsData.indexOf(getTabsData(refid)),1);
	
	if($("#tappage_roommanage_menu_" + title + "").equals(getCurrentTab()))
	{
		var displayTitle = getCurrentTab().nextUntil("[id*=tappage_roommanage_menu_editreserved]").next().attr("title");
		if(displayTitle == null || displayTitle == "")
			displayTitle = getCurrentTab().prevUntil("[id*=tappage_roommanage_menu_editreserved]").prev().attr("title");
		if(displayTitle == null || displayTitle == "")
			DisplayframeMainMenu("Front Desk");
		else
			DisplayframeReserved(displayTitle);
	}
	$("#tappage_roommanage_menu_" + title + "").remove();
	$("img[title="+title+"]").remove();
}
function displaySingleRoomInGroup(dom){
	var Tabs = getCurrentTabData();
	Tabs.viewResIdInGroup = dom.parents("tr:first").attr("resId");
	waitingDialog({});
	loadResData(Tabs.viewResIdInGroup,"0");
}
function backToGroup(){
	var Tabs = getCurrentTabData();
	if(Tabs.getParentGroup == null)
		return;
	for(var o in Tabs)
		if(o!="getParentGroup" && o!="ResData" && o!="fromGroupId" && o!="page" && o!="resId" && o!="type" && o!="ChargeList" && o!="PaymentList" && o!="Task")
			delete Tabs[o];
	delete Tabs.getParentGroup().viewResIdInGroup;
	DisplayDetail();
}

function clearArrayDataRoommanagement(id){
	if (id == "CheckOutListRoomManageMent")
		oldObjArrayCheckout = [];
	else if (id == "CheckInListRoomManageMent")
		oldObjArrayAllReservation = [];
	else if (id == "CheckInPendingListRoomManageMent")
		oldObjArrayCheckin=[];
	else if (id == "TempListRoomManageMent")
		oldObjArrayTemp=[];
	else if (id == "CancelReservationListRoomManageMent")
		oldObjArrayCancel=[];
	else if (id == "CheckOutPendingListRoomManageMent")
		oldObjArrayPendingCheckout=[];
	else if (id == "BookingDepositsListRoomManageMent")
		oldObjArrayDeposits=[];
	else if (id == "PaymentTrackerListRoomManageMent")
		oldObjArrayPaymentTracker=[];
	else if (id == "GuestNameListRoomManageMent")
		oldObjArrayGuest=[];
	else if (id == "CheckOutExpressListRoomManageMent")
		oldObjArrayExpress=[];
	else if (id == "NoShowListRoomManageMent")
		oldObjArrayNoShow=[];
}

function DisplayframeMainMenu(title) {
	$("[for=front]").css("display","");
	$(".addNewRoom").css('display', 'none');// pao
	
	if($("#menulist").attr("style")!=null){
		if($("#menulist").css("display")=="none"){
			$("#menulist").attr("style","")
		}
	}
		
	$("#tabs").find($("[id*=roommanage]")).attr("class", "showdisplay");
	$("[name=edit_groups]").hide();
	$("[name=edit_none_groups]").hide();
	$("#payment-dialog").hide();
	$("#single-payment-dialog").hide();
	if ($("#tabs").find($(".select")).size() == 0)
		$("[title=\"" + title + "\"]").attr("class", "select");
	$("#tappage").find($("[id*=tappage_newpage]")).hide();
	cerltimespan(savedSpan);
}

function DisplayframeReserved(title) {
	$(".select").attr("class","showdisplay");
	$("#tappage_roommanage_menu_" + title + "").attr("class", "select");
	DisplayDetail();
}

//Edit AllTabsData
function changeRoom(resId,roomId)
{
	var room = getObjectFromSharedData(SharedData.Room,roomId);
	var roomtype = getObjectFromSharedData(SharedData.RoomType,room.roomtypeString);
	
	for(var i=0;i<TabsData.length;i++){
		if(TabsData[i].resId == resId && TabsData[i].ResData != null)
		{
			TabsData[i].ResData.roomName = room.roomName;
			TabsData[i].ResData.roomString = room.id;
			TabsData[i].ResData.roomTypeName = roomtype.shortName;
			TabsData[i].ResData.roomTypeString = roomtype.id;
		}
		if(TabsData[i].SplitTable != null && TabsData[i].SplitTable.Object.length > 0)
		{
			var item = getObjectFromDataIndex(TabsData[i].SplitTable.Object,"resId",resId);
			if(item != null)
			{
				item.roomName = room.roomName;
				item.roomId = room.id;
				item.roomTypeShortName = roomtype.shortName;
				item.roomTypeId = roomtype.id;
			}
		}
		if(TabsData[i].type == "Group" && TabsData[i].GroupResvList != null && TabsData[i].GroupResvList.length > 0)
		{
			var listitem = getObjectFromDataIndex(TabsData[i].GroupResvList,"resId",resId);
			if(listitem != null)
			{
				listitem.ResData.roomName = room.roomName;
				listitem.ResData.roomString = room.id;
				listitem.ResData.roomTypeName = roomtype.shortName;
				listitem.ResData.roomTypeString = roomtype.id;
			}
		}
	}
}
function EditResvStatus(resId,statusTitle,statusId)
{
	for(var i=0;i<TabsData.length;i++){
		if(TabsData[i].type == "Group"){
			//Group
			if(TabsData[i].resId == resId){
				TabsData[i].ResData.reservationStatusName = statusTitle;
				TabsData[i].ResData.reservationStatusString = statusId;
			}
			//Single In Group
			var data = getObjectFromDataIndex(TabsData[i].GroupResvList,"resId",resId);
			if(data != null){
				data.ResData.reservationStatusName = statusTitle;
				data.ResData.reservationStatusString = statusId;
			}
		}
		else if(TabsData[i].type == "Single")
		{
			if(TabsData[i].resId == resId){
				TabsData[i].ResData.reservationStatusName = statusTitle;
				TabsData[i].ResData.reservationStatusString = statusId;
			}
		}
	}
}

//check status reservation in group
function checkStatusReservationGroup(data){
	var showStatusResInGroup = "";
	var checkStatus_Reservation= 0;
	var checkStatus_Checkout= 0;
	var checkStatus_Temp = 0;
	var checkStatus_Cancel = 0;
	var checkStatus_Checkin = 0;
	var checkStats_ResCheckIn = 0;
	objArray = data;
	for(var resCount = 0; resCount<objArray.length;resCount++){
		if(objArray[resCount].reservationTitle=="Reserved Rooms")
			checkStatus_Reservation++;
		else if(objArray[resCount].reservationTitle=="Checked-out Rooms")
			checkStatus_Checkout++;
		else if(objArray[resCount].reservationTitle=="Temp Rooms")
			checkStatus_Temp++;
		else if(objArray[resCount].reservationTitle=="Cancel Reservation")
			checkStatus_Cancel++;
		else if(objArray[resCount].reservationTitle=="Checked-in Rooms")
			checkStatus_Checkin++;
		
		if(checkStatus_Cancel>0&&checkStatus_Checkin<=0&&checkStatus_Temp<=0&&checkStatus_Checkout<=0&&checkStatus_Reservation<=0)
			showStatusResInGroup = statusCancel;
		if(checkStatus_Cancel<=0&&checkStatus_Checkin<=0&&checkStatus_Temp<=0&&checkStatus_Checkout>0&&checkStatus_Reservation<=0)
			showStatusResInGroup = statusCheckOut;
		if(checkStatus_Cancel<=0&&checkStatus_Checkin>0&&checkStatus_Temp<=0&&checkStatus_Checkout<=0&&checkStatus_Reservation<=0)
			showStatusResInGroup = statusCheckin;
		if(checkStatus_Cancel<=0&&checkStatus_Checkin<=0&&checkStatus_Temp<=0&&checkStatus_Checkout<=0&&checkStatus_Reservation>0)
			showStatusResInGroup = statusResv;
		if(checkStatus_Checkin>0&&(checkStatus_Temp>0||checkStatus_Checkout>0||checkStatus_Reservation>0||checkStatus_Cancel>0))
			showStatusResInGroup = statusCheckinNoFull;
		if(checkStatus_Reservation>0&&checkStatus_Checkin<=0&&(checkStatus_Temp>0||checkStatus_Checkout>0||checkStatus_Cancel>0))
			showStatusResInGroup = statusSomeReservation;
	}
	return showStatusResInGroup;
}

function noGuestName(){
	simpleDialog(noGuestName_String);
}

function dateRoomManageMent(dateCheckin,dateCheckout){
	$('#'+dateCheckin.checkin).datepicker({
	dateFormat: 'yy-mm-dd',
	showOtherMonths: true,
	showOn: 'both',
	buttonImage: 'http://jqueryui.com/resources/demos/datepicker/images/calendar.gif',
	dayNames: ["อาทิตย์", "จันทร์", "อังคาร", "พุธ", "พฤหัสบดี", "ศุกร์", "เสาร์"],
	dayNamesShort: ["อา.","จ.","อ.","พ.","พฤ.","ศ.","ส."],
	dayNamesMin: ["อ","จ","อ","พ","พ","ศ","ส"],
	monthNames: [Month_Short_Jan,
	             Month_Short_Feb,
	             Month_Short_Mar,
	             Month_Short_Apr,
	             Month_Short_May,
	             Month_Short_Jun,
	             Month_Short_Jul,
	             Month_Short_Aug,
	             Month_Short_Sep,
	             Month_Short_Oct,
	             Month_Short_Nov,
	             Month_Short_Dec],
			onSelect: function(DATE)
			{
				$('#'+dateCheckin.checkin).val($.datepicker.parseDate("yy-mm-dd",DATE).getFormatedString());
				$('#'+dateCheckin.checkin).attr(dateCheckin.atrcheckin,DATE);
				var nextDate = new Date(DATE);
				var	datecheckOutSet = nextDate.addDate(parseInt(0)).toFormatString('yyyy-MM-dd');
				$('#'+dateCheckout.checkout).val($.datepicker.parseDate("yy-mm-dd",datecheckOutSet).getFormatedString());
				$('#'+dateCheckout.checkout).attr(dateCheckout.atrcheckout,datecheckOutSet);
			}
	});
	$('#'+dateCheckout.checkout).datepicker({
		dateFormat: 'yy-mm-dd',
		showOtherMonths: true,
		showOn: 'both',
		buttonImage: 'http://jqueryui.com/resources/demos/datepicker/images/calendar.gif',
			dayNames: ["อาทิตย์", "จันทร์", "อังคาร", "พุธ", "พฤหัสบดี", "ศุกร์", "เสาร์"],
			dayNamesShort: ["อา.","จ.","อ.","พ.","พฤ.","ศ.","ส."],
			dayNamesMin: ["อ","จ","อ","พ","พ","ศ","ส"],
			monthNames: [Month_Short_Jan,
			             Month_Short_Feb,
			             Month_Short_Mar,
			             Month_Short_Apr,
			             Month_Short_May,
			             Month_Short_Jun,
			             Month_Short_Jul,
			             Month_Short_Aug,
			             Month_Short_Sep,
			             Month_Short_Oct,
			             Month_Short_Nov,
			             Month_Short_Dec],
					onSelect: function(DATE)
					{
						$('#'+dateCheckout.checkout).val($.datepicker.parseDate("yy-mm-dd",DATE).getFormatedString());
						$('#'+dateCheckout.checkout).attr(dateCheckout.atrcheckout,DATE);
						if($('#'+dateCheckin.checkin).val()==""||$('#'+dateCheckin.checkin).val()==null){
							var nextDate = new Date(DATE);
							var	datecheckInSet = nextDate.addDate(parseInt(0)).toFormatString('yyyy-MM-dd');
							$('#'+dateCheckin.checkin).val($.datepicker.parseDate("yy-mm-dd",datecheckInSet).getFormatedString());
							$('#'+dateCheckin.checkin).attr(dateCheckin.atrcheckin,datecheckInSet);
						}
					}
		});
}